package com.dream.keigezhushou.Activity.acty.listen;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.dream.keigezhushou.Activity.acty.listen.fragment.MusicWordsFragment;
import com.dream.keigezhushou.Activity.acty.listen.fragment.SingerPictureFragment;
import com.dream.keigezhushou.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HotMusicWordsActivity extends FragmentActivity implements View.OnClickListener {


    @BindView(R.id.ib_return)
    ImageView ibReturn;
    @BindView(R.id.ib_collected)
    ImageView ibCollected;
    @BindView(R.id.textView)
    TextView textView;
    @BindView(R.id.rl_ltitle)
    RelativeLayout rlLtitle;
    @BindView(R.id.text_singer)
    TextView textSinger;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.rb_picture)
    RadioButton rbPicture;
    @BindView(R.id.rb_words)
    RadioButton rbWords;
    @BindView(R.id.radioGroup2)
    RadioGroup radioGroup2;
    @BindView(R.id.iv_previous)
    ImageView ivPrevious;
    @BindView(R.id.iv_words_play)
    ImageView ivWordsPlay;
    @BindView(R.id.iv_next)
    ImageView ivNext;
    @BindView(R.id.lr_play_or_pause)
    RelativeLayout lrPlayOrPause;
    @BindView(R.id.iv_words_love)
    ImageView ivWordsLove;
    @BindView(R.id.iv_words_else)
    ImageView ivWordsElse;
    @BindView(R.id.iv_words_download)
    ImageView ivWordsDownload;
    @BindView(R.id.iv_words_message)
    ImageView ivWordsMessage;
    @BindView(R.id.iv_words_more)
    ImageView ivWordsMore;
    @BindView(R.id.lr_butoom)
    LinearLayout lrButoom;
    @BindView(R.id.timestart)
    TextView timestart;
    @BindView(R.id.timeline)
    SeekBar timeline;
    @BindView(R.id.timeEnd)
    TextView timeEnd;
    @BindView(R.id.lr_seekbar)
    LinearLayout lrSeekbar;
    @BindView(R.id.activity_hot_music_words)
    RelativeLayout activityHotMusicWords;
    private ArrayList<Fragment> fragments;
    private MainPagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_music_words);
        ButterKnife.bind(this);


        setListeners();
        setPagerAapter();
    }

    private void setPagerAapter() {
        fragments = new ArrayList<Fragment>();
        fragments.add(new SingerPictureFragment());
        fragments.add(new MusicWordsFragment());

        pagerAdapter = new MainPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);

    }

    private void setListeners() {

        ivWordsLove.setOnClickListener(this);
        ivWordsElse.setOnClickListener(this);
        ivWordsDownload.setOnClickListener(this);

        ivWordsMessage.setOnClickListener(this);
        ivWordsMore.setOnClickListener(this);


        ibReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ibCollected.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(HotMusicWordsActivity.this, "分享", Toast.LENGTH_SHORT).show();
                finish();
            }
        });


        radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_picture:
                        viewPager.setCurrentItem(0);
                        break;
                    case R.id.rb_words:
                        viewPager.setCurrentItem(1);
                        break;
                }


            }


        });


        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {


            }

            @Override
            public void onPageSelected(int position) {

                switch (position) {
                    case 0:
                        rbPicture.setChecked(true);
                        break;
                    case 1:
                        rbWords.setChecked(true);
                        break;
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }



    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.iv_words_love:
                Toast.makeText(this, "已收藏", Toast.LENGTH_SHORT).show();
                break;
            case R.id.iv_words_else:
                Toast.makeText(this, "随机播放", Toast.LENGTH_SHORT).show();
                break;
            case R.id.iv_words_download:
                Toast.makeText(this, "下载", Toast.LENGTH_SHORT).show();
                break;
            case R.id.iv_words_message:
                Intent intent = new Intent(this, PingLunActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.iv_words_more:
                Toast.makeText(this, "更多", Toast.LENGTH_SHORT).show();
                break;


        }



    }

    private class MainPagerAdapter extends FragmentPagerAdapter {

        public MainPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }


    }
}
